using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Territory object
	/// </summary>
	public partial class TerritoryService : ITerritoryService
	{
		#region ITerritoryService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public TerritoryDTO SelectByPrimaryKey(string territoryid)
		{
			TerritoryPrimaryKeyEventArgs eventArgs = new TerritoryPrimaryKeyEventArgs(territoryid);
			this.OnMockTerritorySelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<TerritoryDTO> RunSelect()
		{
			TerritoryRunSelectEventArgs eventArgs = new TerritoryRunSelectEventArgs();
			this.OnMockTerritoryRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<TerritoryDTO> RunSelect(string linq)
		{
			TerritoryRunSelectLINQEventArgs eventArgs = new TerritoryRunSelectLINQEventArgs(linq);
			this.OnMockTerritoryRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<TerritoryDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			TerritoryRunSelectPagedEventArgs eventArgs = new TerritoryRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockTerritoryRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related EmployeeTerritory objects
		/// </summary>
		public List<EmployeeTerritoryDTO> GetEmployeeTerritoryList(TerritoryDTO item)
		{
			TerritoryDTOEventArgs eventArgs = new TerritoryDTOEventArgs(item);
			this.OnMockGetEmployeeTerritoryList(eventArgs);
			List<EmployeeTerritoryDTO> retval = new List<EmployeeTerritoryDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (EmployeeTerritoryDTO)x));
			return retval;
		}

		/// <summary>
		/// Return the related Region item
		/// </summary>
		public RegionDTO GetRegionItem(TerritoryDTO item)
		{
			RegionDTO retval = new RegionDTO();
			TerritoryDTOEventArgs eventArgs = new TerritoryDTOEventArgs(item);
			this.OnMockGetRegionItem(eventArgs);
			retval = (RegionDTO)eventArgs.ReturnDTOItem;
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(TerritoryDTO dto)
		{
			TerritoryPersistEventArgs eventArgs = new TerritoryPersistEventArgs(dto);
			this.OnMockTerritoryPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<TerritoryDTO> list)
		{
			TerritoryPersistEventArgs eventArgs = new TerritoryPersistEventArgs(list);
			this.OnMockTerritoryPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(TerritoryDTO dto)
		{
			TerritoryDeleteEventArgs eventArgs = new TerritoryDeleteEventArgs(dto);
			this.OnMockTerritoryDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Territory Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<TerritoryPrimaryKeyEventArgs> MockTerritorySelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockTerritorySelectByPrimaryKey(TerritoryPrimaryKeyEventArgs e)
		{
			if (this.MockTerritorySelectByPrimaryKey != null)
				this.MockTerritorySelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<TerritoryRunSelectEventArgs> MockTerritoryRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockTerritoryRunSelect(TerritoryRunSelectEventArgs e)
		{
			if (this.MockTerritoryRunSelect != null)
				this.MockTerritoryRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<TerritoryRunSelectLINQEventArgs> MockTerritoryRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockTerritoryRunSelectLINQ(TerritoryRunSelectLINQEventArgs e)
		{
			if (this.MockTerritoryRunSelectLINQ != null)
				this.MockTerritoryRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<TerritoryRunSelectPagedEventArgs> MockTerritoryRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockTerritoryRunSelectPaged(TerritoryRunSelectPagedEventArgs e)
		{
			if (this.MockTerritoryRunSelectPaged != null)
				this.MockTerritoryRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetEmployeeTerritoryList method
		/// </summary>
		public event EventHandler<TerritoryDTOEventArgs> MockGetEmployeeTerritoryList;

		/// <summary>
		/// The event for the OnMockGetEmployeeTerritoryList method
		/// </summary>
		protected virtual void OnMockGetEmployeeTerritoryList(TerritoryDTOEventArgs e)
		{
			if (this.MockGetEmployeeTerritoryList != null)
				this.MockGetEmployeeTerritoryList(this, e);
		}

		/// <summary>
		/// The event for the GetRegionItem method
		/// </summary>
		public event EventHandler<TerritoryDTOEventArgs> MockGetRegionItem;

		/// <summary>
		/// The event for the OnMockGetRegionItem method
		/// </summary>
		protected virtual void OnMockGetRegionItem(TerritoryDTOEventArgs e)
		{
			if (this.MockGetRegionItem != null)
				this.MockGetRegionItem(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<TerritoryPersistEventArgs> MockTerritoryPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockTerritoryPersist(TerritoryPersistEventArgs e)
		{
			if (this.MockTerritoryPersist != null)
				this.MockTerritoryPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<TerritoryDeleteEventArgs> MockTerritoryDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockTerritoryDelete(TerritoryDeleteEventArgs e)
		{
			if (this.MockTerritoryDelete != null)
				this.MockTerritoryDelete(this, e);
		}

		#endregion

	}
}
